<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
 
     <style>
        #col{
            width: 300px;
            height: 300px;
        }
  
  </style>
</head>
<body>
  <button id="stop">停止变换</button>
  <button id="start">开始变换</button>
  <div id="col"></div>
</body>
</html>
<script>
  var box = document.getElementById("col");
        var stop = document.getElementById("stop");
        var start = document.getElementById("start");
        var timer  =null;

        timer = setInterval(function(){
            var r = Math.floor(Math.random()*256);
            var g = Math.floor(Math.random()*256);
            var b = Math.floor(Math.random()*256);
            box.style.background = "rgb("+r+","+g+","+b+")";
        },500)
        
        stop.onclick=function(){
            clearInterval(timer);
        }
        start.onclick=function(){
            timer = setInterval(function(){
                var r = Math.floor(Math.random()*256);
                var g = Math.floor(Math.random()*256);
                var b = Math.floor(Math.random()*256);
                box.style.background = "rgb("+r+","+g+","+b+")";
            },500)
        }
</script>